package pers.cz.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pers.cz.business.DatabaseDesignBusiness;
import pers.cz.model.DatabaseDesign;
import pers.cz.model.DatabaseDesignConfig;
import pers.cz.model.DatabaseDesignDtlWithBLOBs;
import pers.cz.pub.BeanHelper;
import pers.cz.service.DatabaseDesignService;

import java.util.List;

/**
 * @program: PostGirl-panent
 * @description: 数据建模实现
 * @author: Cheng Zhi
 * @create: 2022-08-14 15:35
 **/
@Transactional
@Service
public class DatabaseDesignServiceImpl implements DatabaseDesignService {

    @Autowired
    BeanHelper beanHelper;

    @Override
    public List<DatabaseDesign> getAllDatabaseDesignByUserId(Integer userId) {
        DatabaseDesignBusiness databaseDesignBusiness = new DatabaseDesignBusiness();
        databaseDesignBusiness.setMapper(beanHelper);
        return databaseDesignBusiness.getAllDatabaseDesignByUserId(userId);
    }

    @Override
    public Integer addNode(DatabaseDesign databaseDesign) {
        DatabaseDesignBusiness databaseDesignBusiness = new DatabaseDesignBusiness();
        databaseDesignBusiness.setMapper(beanHelper);
        return databaseDesignBusiness.addNode(databaseDesign);
    }

    @Override
    public Integer updateNode(DatabaseDesign databaseDesign) {
        DatabaseDesignBusiness databaseDesignBusiness = new DatabaseDesignBusiness();
        databaseDesignBusiness.setMapper(beanHelper);
        return databaseDesignBusiness.updateNode(databaseDesign);
    }

    @Override
    public Integer deleteNode(DatabaseDesign databaseDesign) {
        DatabaseDesignBusiness databaseDesignBusiness = new DatabaseDesignBusiness();
        databaseDesignBusiness.setMapper(beanHelper);
        return databaseDesignBusiness.deleteNode(databaseDesign);
    }

    @Override
    public DatabaseDesignDtlWithBLOBs getDatabaseDesignDtlById(Integer id) {
        DatabaseDesignBusiness databaseDesignBusiness = new DatabaseDesignBusiness();
        databaseDesignBusiness.setMapper(beanHelper);
        return databaseDesignBusiness.queryDtl(id);
    }

    @Override
    public Integer addDtl(DatabaseDesignDtlWithBLOBs databaseDesignDtlWithBLOBs) {
        DatabaseDesignBusiness databaseDesignBusiness = new DatabaseDesignBusiness();
        databaseDesignBusiness.setMapper(beanHelper);
        return databaseDesignBusiness.addDtl(databaseDesignDtlWithBLOBs);
    }

    @Override
    public Integer removeDtl(Integer id) {
        DatabaseDesignBusiness databaseDesignBusiness = new DatabaseDesignBusiness();
        databaseDesignBusiness.setMapper(beanHelper);
        return databaseDesignBusiness.removeDtl(id);
    }

    @Override
    public Integer modifyDel(DatabaseDesignDtlWithBLOBs databaseDesignDtlWithBLOBs) {
        DatabaseDesignBusiness databaseDesignBusiness = new DatabaseDesignBusiness();
        databaseDesignBusiness.setMapper(beanHelper);
        return databaseDesignBusiness.updateDtl(databaseDesignDtlWithBLOBs);
    }

    @Transactional
    @Override
    public Integer addDtlAndNode(DatabaseDesignDtlWithBLOBs databaseDesignDtlWithBLOBs, DatabaseDesign databaseDesign) {
        DatabaseDesignBusiness databaseDesignBusiness = new DatabaseDesignBusiness();
        databaseDesignBusiness.setMapper(beanHelper);
        return databaseDesignBusiness.addDtlAndNode(databaseDesignDtlWithBLOBs, databaseDesign);
    }

    @Override
    public Integer addConf(DatabaseDesignConfig databaseDesignConfig) {
        DatabaseDesignBusiness databaseDesignBusiness = new DatabaseDesignBusiness();
        databaseDesignBusiness.setMapper(beanHelper);
        return databaseDesignBusiness.addConf(databaseDesignConfig);
    }

    @Override
    public Integer udpateConf(DatabaseDesignConfig databaseDesignConfig) {
        DatabaseDesignBusiness databaseDesignBusiness = new DatabaseDesignBusiness();
        databaseDesignBusiness.setMapper(beanHelper);
        return databaseDesignBusiness.updateConf(databaseDesignConfig);
    }

    @Override
    public Integer deleteConf(Long id) {
        DatabaseDesignBusiness databaseDesignBusiness = new DatabaseDesignBusiness();
        databaseDesignBusiness.setMapper(beanHelper);
        return databaseDesignBusiness.deleteConf(id);
    }

    @Override
    public List<DatabaseDesignConfig> queryConfs() {
        DatabaseDesignBusiness databaseDesignBusiness = new DatabaseDesignBusiness();
        databaseDesignBusiness.setMapper(beanHelper);
        return databaseDesignBusiness.queryDatabaseConfs();
    }

    @Transactional
    @Override
    public Integer addField(DatabaseDesignConfig databaseDesignConfig) {
        DatabaseDesignBusiness databaseDesignBusiness = new DatabaseDesignBusiness();
        databaseDesignBusiness.setMapper(beanHelper);
        return databaseDesignBusiness.addFields(databaseDesignConfig);
    }

    @Transactional
    @Override
    public Integer updateField(DatabaseDesignConfig databaseDesignConfig) {
        DatabaseDesignBusiness databaseDesignBusiness = new DatabaseDesignBusiness();
        databaseDesignBusiness.setMapper(beanHelper);
        return databaseDesignBusiness.updateFields(databaseDesignConfig);
    }

    @Override
    public Integer deleteField(DatabaseDesignConfig databaseDesignConfig) {
        DatabaseDesignBusiness databaseDesignBusiness = new DatabaseDesignBusiness();
        databaseDesignBusiness.setMapper(beanHelper);
        return databaseDesignBusiness.deleteFields(databaseDesignConfig);
    }


}
